package com.bawei.base.http

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils

//登录拦截器
@Interceptor(priority = 1)//设置优先级
class LoginInterceptor:IInterceptor {
    override fun init(context: Context?) {
        //初始化，暂时不进行处理
    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        //处理所有ARouter进行的页面跳转
        //需要登录的并且已经登录的跳转到给出的路径页面---------1
        //需要登录的，但没有登录需要先跳转登录页面------------2
        //不需要登录的直接跳转路径页面--------------3
        if ("/user/LoginActivity".equals(postcard?.path)
//            || "/user/LoginPwdActivity".equals(postcard?.path)
//            || "/user/WebActivity".equals(postcard?.path)
            || SPUtils.getInstance().getString("token").isNotEmpty()){
            //直接跳转到给出的路劲页面
            callback?.onContinue(postcard)
        } else {
            ARouter.getInstance().build("/user/LoginActivity").navigation()
        }
    }
}